package com.linkhouse.controller;

import com.linkhouse.common.data.Result;
import com.linkhouse.domain.bo.TbOrderBO;
import com.linkhouse.domain.vo.TbOrderVO;
import com.linkhouse.service.IndexOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/index")
@RestController
@Api("首页新房源同小区近期成交订单接口文档")
public class IndexOrderController {


    @Autowired
    private IndexOrderService oredrService;


    @GetMapping("/{id}")
    @ApiOperation(value = "新房源同近期成交参考订单")           //是否必填        路径传参给path
    @ApiImplicitParam(name = "id",value = "新房id",required = true,paramType = "path")                                    //可以不必填
    public Result query(@PathVariable("id") Long id){
        try {
            List<TbOrderBO> bo = oredrService.query(id);
            List<TbOrderVO> orderVOS = new ArrayList<>();
            for (TbOrderBO tbOrderBO : bo) {
                TbOrderVO vo = new TbOrderVO();
                BeanUtils.copyProperties(tbOrderBO,vo);
                orderVOS.add(vo);
            }
            return Result.OK().setData(orderVOS);
        }catch (Exception e){
            e.printStackTrace();
            return Result.ERROR();
        }
    }
}
